<template>
  <el-dialog
    :title="'订房记录'"
    :close-on-click-modal="false"
    :before-close="onclose"
    :visible.sync="visible"
    :width="'61.8%'">
    <div class="mod-config">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getdata()">
        <el-form-item>
          <el-input v-model="dataForm.key" placeholder="订单号、用户姓名" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getdata()">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :data="dataList"
        border
        v-loading="dataListLoading"
        style="width: 100%;">
        <el-table-column
          v-if="false"
          prop="id"
          header-align="center"
          align="center"
          label="id">
        </el-table-column>
        <el-table-column
          prop="receiptcode"
          header-align="center"
          align="center"
          label="单据编号">
        </el-table-column>
        <el-table-column
          prop="nickname"
          header-align="center"
          align="center"
          label="用户昵称">
        </el-table-column>
        <el-table-column
          prop="typename"
          header-align="center"
          align="center"
          label="房间类型">
        </el-table-column>
        <el-table-column
          prop="roomnum"
          header-align="center"
          align="center"
          label="房间数量">
        </el-table-column>
        <el-table-column
          prop="totalshouldmoney"
          header-align="center"
          align="center"
          label="应收金额">
        </el-table-column>
        <el-table-column
          prop="totalmoney"
          header-align="center"
          align="center"
          label="实收金额">
        </el-table-column>
        <el-table-column
          prop="chargetime"
          header-align="center"
          align="center"
          label="下单时间">
        </el-table-column>
        <el-table-column
          prop="status"
          header-align="center"
          align="center"
          label="订单状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status === 0" size="small" type="danger">待付款</el-tag>
            <el-tag v-if="scope.row.status === 1" size="small" type="warning">待入住</el-tag>
            <el-tag v-if="scope.row.status === 2" size="small" type="success">已入住</el-tag>
            <el-tag v-if="scope.row.status === 3" size="small" type="info">已完成</el-tag>
            <el-tag v-if="scope.row.status === 4" size="small" >已评价</el-tag>
            <el-tag v-if="scope.row.status === 5" size="small" >已取消</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="username"
          header-align="center"
          align="center"
          label="姓名">
        </el-table-column>
        <el-table-column
          prop="phone"
          header-align="center"
          align="center"
          label="联系电话">
        </el-table-column>
        <el-table-column
          prop="starttime"
          header-align="center"
          align="center"
          label="入住时间">
        </el-table-column>
        <el-table-column
          prop="endtime"
          header-align="center"
          align="center"
          label="离开时间">
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </div>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        customerid: 0
      }
    },
    methods: {
      // 获取数据列表
      init (id) {
        this.customerid = id
        this.visible = true
        this.getdata()
      },
      getdata (id) {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/roomreceipt/roomreceipt/orderlist'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key,
            'customerid': this.customerid
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getdata()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getdata()
      },
      onclose () {
        this.visible = false
        this.key = ''
        this.pageIndex = 1
        this.pageSize = 10
        this.totalPage = 0
        this.customerid = 0
      }
    }
  }
</script>
